package com.bgds.sys.module.controller;


import com.bgds.sys.common.excel.EasyExcelExcelUtil;
import com.bgds.sys.common.pagevo.MeasureRecordExcel;
import com.bgds.sys.common.pagevo.Result;
import com.bgds.sys.common.utils.ResultUtil;
import com.bgds.sys.module.entity.MeasureRecord;

import com.bgds.sys.module.service.IMeasureRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lj
 * @since 2020-02-18
 */
@RestController
@Api(tags = "设备精度测量记录")
@RequestMapping("/measureRecord")
public class MeasureRecordController {

    @Autowired
    private IMeasureRecordService iMeasureRecordService;

    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST)
    @ApiOperation(value = "批量添加设备精度测试记录",notes = "批量添加设备精度测试记录",httpMethod = "POST")
    public Result<Object> batchInsert(@RequestBody List<MeasureRecord> measureRecord){

        Boolean flag=iMeasureRecordService.saveOrUpdateBatch(measureRecord);
        if(!flag){
            return new ResultUtil<Object>().setErrorMsg("添加失败!");
        }
        return new ResultUtil<Object>().setSuccessMsg("添加成功!");
    }

    @RequestMapping(value = "/listByConditionPage", method = RequestMethod.GET)
    @ApiOperation(value = "获取设备精度项目测试记录",notes = "获取设备精度项目测试记录",httpMethod = "GET",response = Result.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accuracyId", dataType = "Long",value = "设备精度项目ID"),
    })
    public Result< List<MeasureRecord>> listByConditionPage( Long accuracyId){
        List<MeasureRecord> measureRecords= iMeasureRecordService.listByConditionPage(accuracyId);
        return new ResultUtil< List<MeasureRecord>>().setData(measureRecords);
    }
    @SneakyThrows
    @RequestMapping(value = "/exportExcel", method = RequestMethod.GET)
    @ApiOperation(value = "导出设备精度项目测试记录",notes = "导出设备精度项目测试记录",httpMethod = "GET")
    public void exportExcel( HttpServletResponse response,@RequestParam("ids") List<Long> ids){
       List<MeasureRecordExcel> measureRecordExcels= iMeasureRecordService.listByIds(ids);
       EasyExcelExcelUtil.downLoadExecl(response,"设备精度项目测试记录",measureRecordExcels,MeasureRecordExcel.class);
    }

}

